package org.reliablesource.prism.gef.editor.figures;

import org.eclipse.draw2d.FreeformLayer;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.swt.graphics.Image;


public class ScreenFigure extends FreeformLayer {

	private Image image;

	public ScreenFigure() {
		super();
	}
	
	public void paintFigure(final Graphics graphics){
		super.paintFigure(graphics);
		if(this.image!=null){
			graphics.drawImage(this.image, 0, 0);
		}
	}

	/**
	 * @return Returns the image.
	 */
	public Image getImage() {
		return image;
	}

	/**
	 * @param image The image to set.
	 */
	public void setImage(final Image image) {
		this.image = image;
		this.setBounds(super.getBounds().union(new Rectangle(this.image.getBounds().x, this.image.getBounds().y, this.image.getBounds().width, this.image.getBounds().height)));
	}
	
	// May not the best soluce...
	public Rectangle getFreeformExtent() {
		if(this.image!=null){
			return super.getFreeformExtent().union(new Rectangle(this.image.getBounds().x, this.image.getBounds().y, this.image.getBounds().width, this.image.getBounds().height));
		}
		else{
			return super.getFreeformExtent();	
		}
	}
	
	// May not the best soluce...
	public Rectangle getBounds(){
		if(this.image!=null){
			return super.getBounds().union(new Rectangle(this.image.getBounds().x, this.image.getBounds().y, this.image.getBounds().width, this.image.getBounds().height));
		}
		else{
			return super.getBounds();	
		}}

}
